package com.cskaoyan.processor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.stereotype.Component;

import java.nio.charset.Charset;

/**
 * @author stone
 * @date 2022/10/06 11:15
 */
@Component
public class StringHttpMessageConverterProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof StringHttpMessageConverter) {
            ((StringHttpMessageConverter)bean).setDefaultCharset(Charset.forName("utf-8"));
        }
        return bean;
    }
}
